<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>Dice Roller</title>
	<!-- 
		Copyright 2008 Lucien Stals 

		Licensed under the Apache License, Version 2.0 (the "License"); 
		you may not use this file except in compliance with the License. You may obtain a copy of the License at 

		http://www.apache.org/licenses/LICENSE-2.0 

		Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.	
	-->
	<!-- Source code available http://code.google.com/p/xml-dice-roller/ -->
	
	<link rel="stylesheet" href="css.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>

<body>
	<h1>The Magnificent Dice Roller</h1>

	<div id="intro">
	<p>The Magnificent Dice Roller is a random number generator, using standard <a href="http://en.wikipedia.org/wiki/Dice_notation">dice notation</a>, primarily for use in RPG's like D&amp;D.<br />If rolling standard d20 rolls, use the <a href="#basic">basic</a> button, and just add your modifier, if any.<br /> If you need more control, or other die types, you can type complete dice notation into the <a href="#advanced">advanced</a> box.<br />If you find a bug in this dice roller, please <a href="http://code.google.com/p/xml-dice-roller/issues/list">report it</a>.</p>
	</div>
	
<?php
// display results if we have them...
if(isset($_GET['q']))
{
	echo('<div class="results">');
	require_once('roll.php');
	$q = $_GET['q'];
	if(isset($_GET['mod'])) 
	{
		// only if making a basic roll
		$reg = '/([\+-]?)(\d+)/';
		$mod = $_GET['mod'];
		$mods = preg_match($reg, trim($mod), $matches);
		$operator = "+"; // assume +
			
		if($mods && $mods > 0) // why wouldn't this be true?
		{
			if($matches[1] === "-")
			{
				$operator = "-";
			}
			$q .= ($operator . $matches[2]);
		}
	}

	$allRolls = doRoll($q);
	if(count($allRolls) > 0)
	{
		echo('<dl>');
				$count = count($allRolls);
				for($i=0; $i<$count; ++$i)
				{
	echo('<dt id="req">Request</dt><dd>'.$allRolls[$i]['want'].'</dd>');
	echo('<dt id="raw">Raw</dt><dd>'.$allRolls[$i]['raw'].'</dd>');
	echo('<dt id="mod">Modifier</dt><dd>'.$allRolls[$i]['modifier'].'</dd>');
	echo('<dt id="tot">Total</dt><dd>'.$allRolls[$i]['total'].'</dd>');
	echo('<dt id="ver">Verify</dt><dd><a href="verify.php?h='.$allRolls[$i]['hash'].'">'.$allRolls[$i]['hash'].'</a></dd>');
				}			
			echo('</dl>');
	}
	else
	{
	// TODO: handle errors? give users feedback	
	echo('<p>Oops. There has been some kind of problem. Please try again.</p>');	
	}
	echo('</div>');
}
// end results.
?>	
	
	<div class="inputs">
	
<form action="index.php" method="get" accept-charset="utf-8" id="basicForm">
		<fieldset><legend id="basic">Basic</legend>
			<input type="hidden" name="q" id="basicQ" value="1d20" />
		<p><label for="mod">Roll 1d20  </label>(modifier: <input type="text" name="mod" id="mod" /> )<input type="submit" value="Continue &rarr;" /></p>
			<p id="basicInstructions">E.g. -1 becomes 1d20-1, 1 becomes 1d20+1, +1 becomes 1d20+1, and no input becomes 1d20</p>
		</fieldset>
		</form>


<form action="index.php" method="get" accept-charset="utf-8" id="advancedForm">
	<fieldset><legend id="advanced">Advanced</legend>
	<p><label for="advancedQ">roll: </label><input type="text" name="q" id="advancedQ" /> <input type="submit" value="Continue &rarr;" /></p>
	<div id="advancedInstructions">
	<p>The Advanced input provides quite a bit of power. You can enter standard dice notation for just about any die roll. For example, the following are all legal rolls...</p>
	<ul>
		<li>1d20</li>
		<li>3D6</li>
		<li>1d100</li>
		<li>12d13</li>
	</ul>
	<p>You can add modifiers to rolls, but they <strong>must</strong> be signed (include a + or - sign). e.g...</p>
	<ul>
		<li>1d20+10</li>
		<li>3d6-1</li>
	</ul>
	<p>You can also batch roll in 2 ways. 3d6 would sum the result of the three rolls, returning a single number. But if you want three separate d6 rolls, just use 1d6*3. Or if you want to roll different types of dice, use a comma separated list of rolls. For example, the following are all valid rolls...</p>
	<ul>
		<li>1d6*3</li>
		<li>2d8+1*3</li>
		<li>1d20+8,1d4+2</li>
		<li>1d100+10*3,3d6+1*3</li>
	</ul>
	</div>
	</fieldset>

</div>
</form>

<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<!--<script type="text/javascript" charset="utf-8" src="scripts.js"></script> -->
<?php /*
<!-- google tracking -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-2358431-6");
pageTracker._trackPageview();
} catch(err) {}</script>
*/?>
	
</body>
</html>
